package com.google.android.exoplayer2.extractor.mp3;

import androidx.annotation.Nullable;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.ParserException;
import com.google.android.exoplayer2.extractor.Extractor;
import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.metadata.Metadata.Entry;
import com.google.android.exoplayer2.metadata.id3.MlltFrame;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import java.io.EOFException;
import java.io.IOException;
import o.adv;
import o.adw;
import o.ady;
import o.adz;
import o.aea;
import o.aeb;
import o.aec;
import o.aed;
import o.aef;
import o.aeo;
import o.aep;
import o.aet;
import o.aev;
import o.aew;
import o.aex;
import o.ahm.d;
import o.anc;
import o.anr;

public final class Mp3Extractor implements Extractor {
    private static final d ˊ = aev.ˋ;
    private static final int ˋ = anr.ᐝ("Xing");
    private static final int ˎ = anr.ᐝ("VBRI");
    private static final int ˏ = anr.ᐝ("Info");
    public static final adw ॱ = aet.ॱ;
    private final int ʻ;
    private final anc ʼ;
    private final aed ʽ;
    private int ˊॱ;
    private ady ˋॱ;
    private Metadata ˏॱ;
    private aef ͺ;
    private final aeb ॱˊ;
    private long ॱˋ;
    private e ॱˎ;
    private final long ॱॱ;
    private long ॱᐝ;
    private final aec ᐝ;
    private int ᐝॱ;

    public interface e extends aea {
        long ˋ(long j);

        long ˎ();
    }

    private static /* synthetic */ boolean ˏ(int i, int i2, int i3, int i4, int i5) {
        return (i2 == 67 && i3 == 79 && i4 == 77 && (i5 == 77 || i == 2)) || (i2 == 77 && i3 == 76 && i4 == 76 && (i5 == 84 || i == 2));
    }

    public Mp3Extractor() {
        this(0);
    }

    public Mp3Extractor(int i) {
        this(i, -9223372036854775807L);
    }

    public Mp3Extractor(int i, long j) {
        this.ʻ = i;
        this.ॱॱ = j;
        this.ʼ = new anc(10);
        this.ʽ = new aed();
        this.ᐝ = new aec();
        this.ॱᐝ = -9223372036854775807L;
        this.ॱˊ = new aeb();
    }

    public boolean ˎ(adv o_adv) throws IOException, InterruptedException {
        return ॱ(o_adv, true);
    }

    public void ˏ(ady o_ady) {
        this.ˋॱ = o_ady;
        this.ͺ = this.ˋॱ.ˊ(0, 1);
        this.ˋॱ.ˊ();
    }

    public void ˊ(long j, long j2) {
        this.ˊॱ = 0;
        this.ॱᐝ = -9223372036854775807L;
        this.ॱˋ = 0;
        this.ᐝॱ = 0;
    }

    public void ॱ() {
    }

    public int ˎ(adv o_adv, adz o_adz) throws IOException, InterruptedException {
        if (this.ˊॱ == 0) {
            try {
                ॱ(o_adv, false);
            } catch (EOFException e) {
                return -1;
            }
        }
        if (this.ॱˎ == null) {
            e ˏ = ˏ(o_adv);
            e ˎ = ˎ(this.ˏॱ, o_adv.ˊ());
            if (ˎ != null) {
                this.ॱˎ = ˎ;
            } else if (ˏ != null) {
                this.ॱˎ = ˏ;
            }
            if (this.ॱˎ == null || !(this.ॱˎ.ˊ() || (this.ʻ & 1) == 0)) {
                this.ॱˎ = ॱ(o_adv);
            }
            this.ˋॱ.ˎ(this.ॱˎ);
            this.ͺ.ˎ(Format.ˏ(null, this.ʽ.ˏ, null, -1, 4096, this.ʽ.ˋ, this.ʽ.ˊ, -1, this.ᐝ.ˏ, this.ᐝ.ॱ, null, null, 0, null, (this.ʻ & 2) != 0 ? null : this.ˏॱ));
        }
        return ˊ(o_adv);
    }

    private int ˊ(adv o_adv) throws IOException, InterruptedException {
        int ॱᐝ;
        if (this.ᐝॱ == 0) {
            o_adv.ˏ();
            if (ˋ(o_adv)) {
                return -1;
            }
            this.ʼ.ˋ(0);
            ॱᐝ = this.ʼ.ॱᐝ();
            if (!ˊ(ॱᐝ, (long) this.ˊॱ) || aed.ˊ(ॱᐝ) == -1) {
                o_adv.ॱ(1);
                this.ˊॱ = 0;
                return 0;
            }
            aed.ˋ(ॱᐝ, this.ʽ);
            if (this.ॱᐝ == -9223372036854775807L) {
                this.ॱᐝ = this.ॱˎ.ˋ(o_adv.ˊ());
                if (this.ॱॱ != -9223372036854775807L) {
                    long ˋ = this.ॱˎ.ˋ(0);
                    this.ॱᐝ = (this.ॱॱ - ˋ) + this.ॱᐝ;
                }
            }
            this.ᐝॱ = this.ʽ.ॱ;
        }
        ॱᐝ = this.ͺ.ˏ(o_adv, this.ᐝॱ, true);
        if (ॱᐝ == -1) {
            return -1;
        }
        this.ᐝॱ -= ॱᐝ;
        if (this.ᐝॱ > 0) {
            return 0;
        }
        this.ͺ.ˋ(((this.ॱˋ * 1000000) / ((long) this.ʽ.ˊ)) + this.ॱᐝ, 1, this.ʽ.ॱ, 0, null);
        this.ॱˋ += (long) this.ʽ.ᐝ;
        this.ᐝॱ = 0;
        return 0;
    }

    private boolean ॱ(adv o_adv, boolean z) throws IOException, InterruptedException {
        int i;
        int i2;
        int i3;
        int i4;
        int i5 = z ? 16384 : WXMediaMessage.MINI_PROGRAM__THUMB_LENGHT;
        o_adv.ˏ();
        if (o_adv.ˊ() == 0) {
            if ((this.ʻ & 2) == 0) {
                i = 1;
            } else {
                boolean z2 = false;
            }
            this.ˏॱ = this.ॱˊ.ˏ(o_adv, i != 0 ? null : ˊ);
            if (this.ˏॱ != null) {
                this.ᐝ.ॱ(this.ˏॱ);
            }
            i = (int) o_adv.ˎ();
            if (!z) {
                o_adv.ॱ(i);
            }
            i2 = i;
            i3 = 0;
            i4 = 0;
            i = 0;
        } else {
            i = 0;
            i2 = 0;
            i3 = 0;
            i4 = 0;
        }
        while (!ˋ(o_adv)) {
            this.ʼ.ˋ(0);
            int ॱᐝ = this.ʼ.ॱᐝ();
            if (i3 == 0 || ˊ(ॱᐝ, (long) i3)) {
                int ˊ = aed.ˊ(ॱᐝ);
                if (ˊ != -1) {
                    i4++;
                    if (i4 != 1) {
                        if (i4 == 4) {
                            break;
                        }
                    }
                    aed.ˋ(ॱᐝ, this.ʽ);
                    i3 = ॱᐝ;
                    o_adv.ˊ(ˊ - 4);
                }
            }
            i3 = i + 1;
            if (i == i5) {
                if (z) {
                    return false;
                }
                throw new ParserException("Searched too many bytes.");
            } else if (z) {
                o_adv.ˏ();
                o_adv.ˊ(i2 + i3);
                i = i3;
                i4 = 0;
                i3 = 0;
            } else {
                o_adv.ॱ(1);
                i = i3;
                i4 = 0;
                i3 = 0;
            }
        }
        if (i4 <= 0) {
            throw new EOFException();
        }
        if (z) {
            o_adv.ॱ(i2 + i);
        } else {
            o_adv.ˏ();
        }
        this.ˊॱ = i3;
        return true;
    }

    private boolean ˋ(adv o_adv) throws IOException, InterruptedException {
        if ((this.ॱˎ == null || o_adv.ˎ() != this.ॱˎ.ˎ()) && o_adv.ˎ(this.ʼ.ˏ, 0, 4, true)) {
            return false;
        }
        return true;
    }

    private e ˏ(adv o_adv) throws IOException, InterruptedException {
        anc o_anc = new anc(this.ʽ.ॱ);
        o_adv.ˎ(o_anc.ˏ, 0, this.ʽ.ॱ);
        int i = (this.ʽ.ˎ & 1) != 0 ? this.ʽ.ˋ != 1 ? 36 : 21 : this.ʽ.ˋ != 1 ? 21 : 13;
        int ॱ = ॱ(o_anc, i);
        e ˋ;
        if (ॱ == ˋ || ॱ == ˏ) {
            ˋ = aew.ˋ(o_adv.ॱ(), o_adv.ˊ(), this.ʽ, o_anc);
            if (!(ˋ == null || this.ᐝ.ˎ())) {
                o_adv.ˏ();
                o_adv.ˊ(i + 141);
                o_adv.ˎ(this.ʼ.ˏ, 0, 3);
                this.ʼ.ˋ(0);
                this.ᐝ.ॱ(this.ʼ.ˏॱ());
            }
            o_adv.ॱ(this.ʽ.ॱ);
            if (ˋ == null || ˋ.ˊ() || ॱ != ˏ) {
                return ˋ;
            }
            return ॱ(o_adv);
        } else if (ॱ == ˎ) {
            ˋ = aex.ॱ(o_adv.ॱ(), o_adv.ˊ(), this.ʽ, o_anc);
            o_adv.ॱ(this.ʽ.ॱ);
            return ˋ;
        } else {
            o_adv.ˏ();
            return null;
        }
    }

    private e ॱ(adv o_adv) throws IOException, InterruptedException {
        o_adv.ˎ(this.ʼ.ˏ, 0, 4);
        this.ʼ.ˋ(0);
        aed.ˋ(this.ʼ.ॱᐝ(), this.ʽ);
        return new aep(o_adv.ॱ(), o_adv.ˊ(), this.ʽ);
    }

    private static boolean ˊ(int i, long j) {
        return ((long) (-128000 & i)) == (-128000 & j);
    }

    private static int ॱ(anc o_anc, int i) {
        if (o_anc.ॱ() >= i + 4) {
            o_anc.ˋ(i);
            int ॱᐝ = o_anc.ॱᐝ();
            if (ॱᐝ == ˋ || ॱᐝ == ˏ) {
                return ॱᐝ;
            }
        }
        if (o_anc.ॱ() >= 40) {
            o_anc.ˋ(36);
            if (o_anc.ॱᐝ() == ˎ) {
                return ˎ;
            }
        }
        return 0;
    }

    @Nullable
    private static aeo ˎ(Metadata metadata, long j) {
        if (metadata != null) {
            int ˋ = metadata.ˋ();
            for (int i = 0; i < ˋ; i++) {
                Entry ˋ2 = metadata.ˋ(i);
                if (ˋ2 instanceof MlltFrame) {
                    return aeo.ˋ(j, (MlltFrame) ˋ2);
                }
            }
        }
        return null;
    }
}
